import { api } from '@/utils/request'
import type { 
  Permission, 
  PermissionTree, 
  PermissionPageParams,
  PageResult,
  ApiResponse,
  LoginForm,
  LoginResponse
} from '@/types'

export class PermissionService {

  /**
   * 分页查询权限列表
   */
  static async getPermissionPage(params: PermissionPageParams): Promise<PageResult<Permission>> {
    const response = await api.post<PageResult<Permission>>('/auth/api-admin/authPermission/page', params)
    return response.data
  }

  /**
   * 获取权限详情
   */
  static async getPermissionDetail(id: number): Promise<Permission> {
    const response = await api.get<Permission>(`/auth/api-admin/authPermission/get/${id}`)
    return response.data
  }

  /**
   * 新增权限
   */
  static async addPermission(permissionData: Partial<Permission>): Promise<boolean> {
    const response = await api.post<boolean>('/auth/api-admin/authPermission/create', permissionData)
    return response.data
  }

  /**
   * 更新权限
   */
  static async updatePermission(permissionData: Partial<Permission>): Promise<boolean> {
    const response = await api.post<boolean>('/auth/api-admin/authPermission/update', permissionData)
    return response.data
  }

  /**
   * 删除权限
   */
  static async deletePermission(id: number): Promise<boolean> {
    const response = await api.delete<boolean>(`/auth/api-admin/authPermission/delete/${id}`)
    return response.data
  }

  /**
   * 获取权限树形结构
   */
  static async getPermissionTree(): Promise<PermissionTree[]> {
    const response = await api.get<PermissionTree[]>('/auth/api-admin/authPermission/getPermissionTree')
    return response.data
  }
}

// 默认导出单例实例
export const permissionService = PermissionService 